/****************************************************************************
 * FILE NAME: 		generic.c
 * 
 * PROJECT NAME: 	EGR330_Project
 * TEAM MEMBERS: 	Kevin Vermeer
 * 					Brandon Ross
 *					Tyler Selk
 *
 *
 * CREATED: 		31 July 2011 (Brandon Ross)
 * LAST MODIFIED: 	
 * 
 * DESCRIPTION:		Handles generic functions and register manipulations
 ****************************************************************************/

#include <avr/io.h>
#include <inttypes.h>

#include "generic.h"

uint8_t setRegister(
	uint8_t register_value, 
	uint8_t clear_mask,
	uint8_t set_mask,
	uint8_t register_position)
{
	return ((register_value & ~clear_mask) | (set_mask << register_position));
}

uint8_t setBit(
	uint8_t register_value,
	uint8_t bit_mask)
{
	return (register_value | bit_mask);
}

uint8_t clearBit(
	uint8_t register_value,
	uint8_t bit_mask)
{
	return (register_value & ~bit_mask);
}

uint8_t toggleBit(
	uint8_t register_value,
	uint8_t bit_mask)
{
	return (register_value ^ bit_mask);
}

uint8_t isBitSet(
	uint8_t register_value,
	uint8_t bit_mask)
{
	return (((register_value & bit_mask)!=0) ? TRUE : FALSE);
}

uint8_t isBitClear(
	uint8_t register_value,
	uint8_t bit_mask)
{
	return (((register_value & bit_mask)==0) ? TRUE : FALSE);
}
